package Offer.offer2020;

import domain.TreeNode;

import java.util.LinkedList;
import java.util.List;

/**
 * 从上往下打印列表
 * 层序遍历
 * @Author: leiwenkang02
 * @Date: 2020/3/27 12:13 下午
 */
public class Test23 {
    public void printTree(TreeNode root) {
        if (root == null) {
            return;
        }
        List<TreeNode> list = new LinkedList<>();

        list.add(root);
        while (!list.isEmpty()) {
            TreeNode p = list.remove(0);
            System.out.print(p.val);
            System.out.print(" ");
            if (p.left != null) {
                list.add(p.left);
            }
            if (p.right != null) {
                list.add(p.right);
            }
        }
    }
}
